package com.youku.plugins.endcardV4New.view
{
   import flash.display.Sprite;
   import com.youku.plugins.endcardV4New.model.data.RelativeVideoData;
   import flash.text.TextField;
   import flash.display.MovieClip;
   import com.youku.baseUI.BasePlayerButton;
   import com.youku.utils.AssetUtil;
   import com.youku.plugins.endcardV4New.EndCardFont;
   import flash.text.TextFieldAutoSize;
   import flash.text.TextFormat;
   
   public class RelativePreviewBoxInfo extends Sprite
   {
      
      public function RelativePreviewBoxInfo(param1:RelativeVideoData) {
         super();
         this._relativeVideodata = param1;
         this.init();
      }
      
      private var _relativeVideodata:RelativeVideoData;
      
      private var _width:Number;
      
      private var _height:Number;
      
      private var _background:Sprite;
      
      private var _title:TextField;
      
      private var _playCountsIcon:MovieClip;
      
      private var _playCounts:TextField;
      
      private var _commentIcon:MovieClip;
      
      private var _comment:TextField;
      
      private var _totalTime:TextField;
      
      private var _playButton:BasePlayerButton;
      
      private function init() : void {
         this._width = 200;
         this._height = 110;
         this._background = new Sprite();
         this._background.graphics.beginFill(0,0.7);
         this._background.graphics.drawRect(0,0,this._width,this._height);
         this._background.graphics.endFill();
         addChild(this._background);
         this._title = AssetUtil.getTextField();
         this._title.width = 190;
         this._title.height = 48;
         this._title.defaultTextFormat = EndCardFont.FONT_VIDEO_TITLE;
         this._title.mouseEnabled = false;
         this._title.text = this._relativeVideodata.title;
         addChild(this._title);
         this._playCountsIcon = AssetUtil.getAsset("E_play_counts_icon") as MovieClip;
         this._playCountsIcon.width = 12;
         this._playCountsIcon.height = 12;
         addChild(this._playCountsIcon);
         this._playCounts = AssetUtil.getTextField(false);
         this._playCounts.defaultTextFormat = EndCardFont.FONT_VIDEO_PLAY_COUNTS;
         this._playCounts.mouseEnabled = false;
         this._playCounts.autoSize = TextFieldAutoSize.LEFT;
         this._playCounts.text = this.setNum(this._relativeVideodata.totalPV);
         addChild(this._playCounts);
         this._commentIcon = AssetUtil.getAsset("E_comment_icon") as MovieClip;
         this._commentIcon.width = 12;
         this._commentIcon.height = 12;
         addChild(this._commentIcon);
         this._comment = AssetUtil.getTextField(false);
         this._comment.defaultTextFormat = EndCardFont.FONT_VIDEO_COMMENT;
         this._comment.mouseEnabled = false;
         this._comment.autoSize = TextFieldAutoSize.LEFT;
         this._comment.text = this.setNum(this._relativeVideodata.totalComment);
         addChild(this._comment);
         this._totalTime = AssetUtil.getTextField(false);
         this._totalTime.defaultTextFormat = EndCardFont.FONT_VIDEO_TOTAL_TIME;
         this._totalTime.mouseEnabled = false;
         this._totalTime.autoSize = TextFieldAutoSize.LEFT;
         this._totalTime.text = this.setTimeFormat(this._relativeVideodata.seconds);
         addChild(this._totalTime);
         this._playButton = AssetUtil.getStyleButton("P_Button_OK");
         this._playButton.hardOffset = -2;
         var _loc1_:TextFormat = EndCardFont.FONT_BUTTON_CONFIRM;
         _loc1_.letterSpacing = 5;
         this._playButton.setStyle("textFormat",_loc1_);
         this._playButton.label = "播放";
         this._playButton.setSize(56,24);
         this._playButton.fixLeftAlign = 12;
         addChild(this._playButton);
         this.layout();
      }
      
      public function setWH(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this._background.width = this._width;
         this._background.height = this._height;
         this.layout();
      }
      
      private function layout() : void {
         this._background.x = 0;
         this._background.y = 0;
         this._title.x = 5;
         this._title.y = 8;
         this._playCountsIcon.x = 7;
         this._playCounts.x = 20;
         if(this._title.numLines == 1)
         {
            this._playCountsIcon.y = 40;
            this._playCounts.y = 36;
         }
         else
         {
            this._playCountsIcon.y = 57;
            this._playCounts.y = 53;
         }
         this._commentIcon.x = 80;
         this._commentIcon.y = this._playCountsIcon.y;
         this._comment.x = 95;
         this._comment.y = this._playCounts.y;
         this._totalTime.x = this._width - this._totalTime.textWidth - 10;
         this._totalTime.y = this._playCounts.y;
         this._playButton.x = 7;
         this._playButton.y = 79;
      }
      
      private function setNum(param1:Number) : String {
         var _loc2_:String = String(param1);
         var _loc3_:int = _loc2_.length;
         if(_loc3_ < 4)
         {
            return _loc2_;
         }
         if(_loc3_ == 4)
         {
            return _loc2_.charAt(0) + "," + _loc2_.slice(1,4);
         }
         if(_loc3_ > 4 && _loc3_ < 9)
         {
            return (param1 / 10000).toFixed(1) + "万";
         }
         if(_loc3_ >= 9)
         {
            return (param1 / 100000000).toFixed(1) + "亿";
         }
         return _loc2_;
      }
      
      private function setTimeFormat(param1:Number) : String {
         var _loc2_:* = "";
         var _loc3_:int = param1 % 60;
         var _loc4_:int = int(param1 / 60);
         _loc2_ = _loc2_ + (_loc4_ < 10?"0" + _loc4_:_loc4_);
         _loc2_ = _loc2_ + ":";
         _loc2_ = _loc2_ + (_loc3_ < 10?"0" + _loc3_:_loc3_);
         return _loc2_;
      }
   }
}
